package com.sdry.project.service.impl;

import com.sdry.project.entity.ProjectEntity;
import com.sdry.project.mapper.ProjectMapper;
import com.sdry.project.service.ProjectService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sdry.untils.UserContext;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author chenBin
 * @since 2020-08-10
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, ProjectEntity> implements ProjectService {

    @Resource
    private ProjectMapper projectMapper;

    @Override
    public boolean updateById(Long projectId, String awardsAdmin) {
        ProjectEntity projectEntity = new ProjectEntity();
        if (projectId != null) {
            ProjectEntity projectEntity1 = projectMapper.selectById(projectId);
            //原等级
            projectEntity.setPrimaryAwardsResult(projectEntity1.getAwardsresult());
            projectEntity.setId(projectId);
            projectEntity.setAwardsresult(awardsAdmin);
            int updateById = projectMapper.updateById(projectEntity);
            return updateById > 0;
        }
        return false;
    }

    @Override
    public void importDataExcel(List<ProjectEntity> dataList) {
        for (ProjectEntity projectEntity : dataList) {
            projectMapper.insert(projectEntity);
        }

    }

    @Override
    public List<ProjectEntity> listByExpoer(Object projectName) {
        Long userId = UserContext.getSessionUserIdByServiceImpl();
        return projectMapper.listByExport(projectName,userId);
    }

    @Override
    public List<ProjectEntity> listByExpoer2021(Object projectName, String idea) {
        Long userId = UserContext.getSessionUserIdByServiceImpl();
        if (userId == 35L) {
            userId = null;
        }
        return projectMapper.listByExpoer2021(projectName,userId,idea);

    }
}
